$(document).ready(function(){
    // 时间选择控件---显示年月日
    $('.calendarTime').mobiscroll().date({
        theme : 'ios',
        lang : 'zh',
        display : 'bottom',
        dateFormat : 'yy-mm-dd',
        showScrollArrows: true
    });

    $(".edit-basic-info li").each(function(){
        var Li = $(this)
        var LiW = Li.width();
        var SpanW = Li.find("span").width();
        Li.find("input,.selectb").width(LiW-SpanW-2);
    });
    
    /*选择上课日*/
    selectSchoolDay($(".class-day span"));

    $("#submitBtn").click(function(){
        verification_Null()//验证输入

        if(flag){
            var order_num = $("#order_num").val();
            var p_id = $("#p_id").val();

            /*提交信息*/
            var datas = {
                interface:'IcbcPay@insuranceInfo',
                order_num: order_num,
                p_id:p_id,
                userName: userName,
                idCardNo:idCardNo,
                phone:phone,
                userEmail:userEmail,
                userEducation: userEducation,
                userSchool: userSchool,
                user_course_time:classHour,
                classRoom:classRoom,
                graduationTime:graduationTime,
                startTime:startTime,
                endTime:endTime,
                schoolDay:schoolDay,
            };
            common.ajax({
                data: datas,
                success: function (data) {
                    if (data.status == '2000') {
                        location.href = '/pay/?order_num='+order_num;
                    } else if (data.status == '5000') {
                        falert(data.msg);
                    } else if (data.status == '5003') {
                        falert(data.msg);
                    }
                }
            });
        }
    })
});

var userName = '',
    idCardNo = '',
    phone = '',
    userEmail = '',
    userEducation = '',
    userSchool = '',
    classHour = '',
    classRoom = '',
    graduationTime = '',
    startTime = '',
    endTime = '',
    schoolDay = '';
var flag = true;

/*验证是否为空、是否符合规则*/
function verification_Null(){
    userName = $.trim($("#userName").val());/*被保人姓名*/
    idCardNo = $.trim($("#idCardNo").val());/*被保人证件号码*/
    phone = $.trim($("#userPhone").val());/*被保人手机号*/

    userEmail = $.trim($("#userEmail").val());/*被保人邮箱*/
    userEducation = $.trim($("#userEducation").val());/*被保人学历*/

    userSchool = $.trim($("#userSchool").val());/*就读学校*/
    classHour = $.trim($("#classHour").val());/*课时*/
    classRoom = $.trim($("#classRoom").val());/*班级*/
    graduationTime = $.trim($("#graduationTime").val());/*毕业时间*/
    startTime = $.trim($("#startTime").val());/*课程开始时间*/
    endTime = $.trim($("#endTime").val());/*课程结束时间*/
    schoolDay = $("#schoolDay").html();

    if(userName == ''){
        falert("请输入被保人姓名");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(idCardNo == ''){
        falert("请输入被保人证件号码");
        flag=false;
        return false;
    }else{
        flag = true
    }
    /*手机号*/
    if(phone == ''){
        falert("请输入被保人手机号");
        flag=false;
        return false;
    } else if (!Regexs.allphpne.test(phone)) { /*手机号正则校验*/
        falert("请输入正确的手机号码");  
        flag=false;
        return false; 
    } else {
        flag = true
    }

    /*邮箱*/
    if(userEmail == ''){
        falert("请输入被保人邮箱");
        flag=false;
        return false;
    } else if (!Regexs.email.test(userEmail)) { /*邮箱正则校验*/
        falert("请输入正确的邮箱");  
        flag=false;
        return false; 
    } else {
        flag = true
    }

    if(userEducation == ''){
        falert("请选择学历");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(userSchool == ''){
        falert("请输入学校名称");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(classHour == ''){
        falert("请输入培训课时");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(classRoom == ''){
        falert("请输入专业");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(graduationTime == ''){
        falert("请选择毕业时间");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(startTime == ''){
        falert("请选择课程开始时间");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(endTime == ''){
        falert("请选择课程结束时间");
        flag=false;
        return false;
    }else{
        flag = true
    }

    if(schoolDay == ''){
        falert("请选择上课日");
        flag=false;
        return false;
    }else{
        flag = true
    }
}

/*选择上课日*/
function selectSchoolDay(obj){
    obj.click(function(){
        var index = $(this).index();
        if($(this).hasClass("cur")){
            $(this).removeClass("cur");
        } else {
            $(this).addClass("cur");
        }

        var html = "";
        $(".class-day span.cur").each(function(){
            html += ('周' + $(this).html() + ',');
        })

        var s = html;
        s=s.substring(0,s.length-1); //删除最后一个逗号

        $("#schoolDay").html(s);
    });
}
